﻿/********************************************************************************
** @ Date:2024/04/25
** @ Author: AoZhiQiang
** @ Description: 设备关注单例类
** @ Version:1.0.0
** @ Fun:
********************************************************************************/
#ifndef CDevFollow_H
#define CDevFollow_H
#include <QObject>
#include <QMap>
#include <QMutex>
#include <QQueue>
#include <QDateTime>

//设备关注参数
struct SDevFollowParam
{
	QString sCtrIp;                //关注该设备的机器IP
	int nPort;                     //关注该设备的机器Port
	QString sDevGuid;              //设备Guid
	SDevFollowParam()
	{
		sCtrIp = "";               //关注该设备的机器IP
		nPort = 502;               //关注该设备的机器Port
		sDevGuid = "";             //设备Guid
	}
};

class CDevFollow  : public QObject
{
	Q_OBJECT

public:
	CDevFollow(QObject *parent = nullptr);
	~CDevFollow();

	/*(静态)*/
	static CDevFollow* getInstance();                     	//获取单例
	/*设备关注*/
	void addDevInFllow(SDevFollowParam stParam);            //添加到关注列表
	void removeDevFollow(QString sDevGuid);                 //移除关注
	bool isExistFollow(QString sDevGuid);                   //是否存在关注
	SDevFollowParam getDevFollowParam(QString sDevGuid);    //获得设备关注信息

public:
	static CDevFollow* m_pInstance;                         //单例
	static QMutex m_locker;                                 //锁

private:
	QMap<QString, SDevFollowParam> m_mapDevFollow;          //设备关注集合

private:
private:
	//垃圾回收类  释放单列指针
	class CDevFollowTrush
	{
	public:
		~CDevFollowTrush()
		{
			if (CDevFollow::m_pInstance != nullptr)
			{
				delete  CDevFollow::m_pInstance;
				CDevFollow::m_pInstance = nullptr;
			}
		}
	};

	static CDevFollowTrush uTrush;   //定义静态变量  系统结束自动释放该类  调用析构方法从而释放指针
};

#endif 